﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Rule;
using Engine.RuleEditor.Properties;
using System.Windows.Forms;

namespace Engine.RuleEditor
{
    public class FormSkillTypesEditor : FormAttributeTypesEditor
    {
        private List<SkillType> skillTypes;
        public List<SkillType> SkillTypes
        {
            get { return skillTypes; }
            set { skillTypes = value; }
        }

        public FormSkillTypesEditor(List<SkillType> skillTypes)
            : base("Skill Types Editor", Resources.chart)
        {
            SkillTypes = skillTypes;

            for (int sIndex = 0; sIndex < SkillTypes.Count; sIndex++)
            {
                SkillType skillType = SkillTypes[sIndex];

                DataGridViewTextBoxCell cellName = new DataGridViewTextBoxCell();
                cellName.Value = skillType.Name;
                DataGridViewTextBoxCell cellDescription = new DataGridViewTextBoxCell();
                cellDescription.Value = skillType.Description;
                DataGridViewRow row = new DataGridViewRow();
                row.Cells.Add(cellName);
                row.Cells.Add(cellDescription);

                DataGridTypes.Rows.Add(row);
            }
        }

        protected override void buttonSave_Click(object sender, EventArgs e)
        {
            SkillTypes.Clear();
            for (int rIndex = 0; rIndex < DataGridTypes.Rows.Count - 1; rIndex++)
            {
                object objName = DataGridTypes[0, rIndex].Value;
                object objDescription = DataGridTypes[1, rIndex].Value;
                string name = (objName != null ? objName.ToString() : null);
                string description = (objDescription != null ? objDescription.ToString() : null);
                SkillType skillType = new SkillType(name, description);
                SkillTypes.Add(skillType);
            }
            base.buttonSave_Click(sender, e);
        }
    }
}
